import functools
import time


def call_time(f):
    @functools.wraps(f)
    def wrapper(*args, **kw):
        start = time.time()
        f(*args, **kw)
        end = time.time()
        return end - start

    return wrapper


def with_metaclass(meta, *bases):
    class metaclass(meta):
        __call__ = type.__call__
        __init__ = type.__init__

        def __new__(cls, name, this_bases, d):
            if this_bases is None:
                return type.__new__(cls, name, (), d)
            return meta(name, bases, d)

    return metaclass('temporary_class', None, {})


def super_init(init):
    @functools.wraps(init)
    def wrapper_init(self, *args, **kwargs):
        for _ in self.__class__.__mro__[1:-1]:
            _.__init__(self)
        init(self, *args, **kwargs)

    return wrapper_init

# def timeout(max_time):
